var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
import React, { useEffect, Fragment } from "react";
import { View, Text } from "@tarojs/components";
import Taro from "@tarojs/taro";
import "./index.scss";
import useStatusBar from "../../uses/useStatusBar";
import { AtIcon } from "taro-ui";
import { IS_IOS } from "../../utils/system";
/**
 * Nav 导航栏组件
 */
var Nav = function (_a) {
    var title = _a.title, leftView = _a.leftView, rightView = _a.rightView, _b = _a.overlay, overlay = _b === void 0 ? true : _b, styles = _a.styles, onBack = _a.onBack, _c = _a.leftStyle, leftStyle = _c === void 0 ? { color: "#000" } : _c, middleStyle = _a.middleStyle, renderCenter = _a.renderCenter, rootPath = _a.rootPath, cbNavHeight = _a.cbNavHeight;
    var _d = __read(useStatusBar(), 1), statusHeight = _d[0];
    var barHeight = IS_IOS ? 44 : 48;
    useEffect(function () {
        cbNavHeight && cbNavHeight(barHeight + statusHeight);
    }, []);
    var renderLet = function () {
        var content = leftView ? (leftView) : (React.createElement(AtIcon, { value: "chevron-left", size: "20", color: leftStyle.color }));
        return (React.createElement(View, { className: "left-wrapper", style: leftStyle, onClick: function () {
                if (onBack) {
                    return onBack();
                }
                Taro.navigateBack();
            } }, content));
    };
    var renderRight = function () {
        var content = rightView ? rightView : null;
        return content;
    };
    return (React.createElement(Fragment, null,
        React.createElement(View, { className: "navbar", style: __assign({ paddingTop: statusHeight + "px", height: barHeight + "px" }, styles) },
            React.createElement(View, { className: "navbar-inner" },
                renderLet(),
                renderCenter ? (renderCenter()) : (React.createElement(Text, { className: "title", style: middleStyle }, title)),
                renderRight())),
        overlay ? (React.createElement(View, { style: {
                height: barHeight + statusHeight
            } })) : null));
};
export default Nav;
